/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.gwxs;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;

/**
 *
 * @author Austin
 */
public class test1 {
    
    public static void main(String[] args) {
        
        try {
            String[] strs = "<Msg><MsgID>1511334250</MsgID><From><![CDATA[wxid_2zrlgjlimeta21]]></From><FromUin>2357028736</FromUin><To><![CDATA[5527067147@chatroom]]></To><Type>43</Type><Content><![CDATA[<?xml version=\"1.0\"?><msg>	<videomsg aeskey=\"6a1bb857666249619f09f0563a57eadd\" cdnthumbaeskey=\"\" cdnvideourl=\"306b0201000464306202010002048c7d678002033d11ff020469c9c0b702045a152169043d617570766964656f5f396362366365383239663161656531385f313531313333343234365f3135303430363232313131373862663165336136383332320204010400040201000400\" cdnthumburl=\"306b0201000464306202010002048c7d678002033d11ff020469c9c0b702045a152169043d617570766964656f5f396362366365383239663161656531385f313531313333343234365f3135303430363232313131373862663165336136383332320204010400040201000400\" length=\"0\" playlength=\"1\" cdnthumblength=\"24643\" cdnthumbwidth=\"550\" cdnthumbheight=\"412\" fromusername=\"wxid_2zrlgjlimeta21\" md5=\"ba089e53fcea9c702e6b3a40b0136498\" newmd5=\"\" isad=\"0\" /></msg>]]></Content><FromTime>1511334250</FromTime><Chatroom>5527067147</Chatroom><MediaID>0</MediaID><ClientIP><![CDATA[222.44.82.5]]></ClientIP><md5><![CDATA[ba089e53fcea9c702e6b3a40b0136498]]></md5></Msg>".split("</Msg>");
            for (String s : strs) {
                if (s.trim().isEmpty()) {
                    continue;
                }
                JSONObject xmlJSONObj = XML.toJSONObject(s + "</Msg>");
                System.out.println(xmlJSONObj.get("Msg").toString());
//                JSONObject json = new JSONObject(xmlJSONObj.get("Msg").toString());
//                System.out.println(json.get("Content"));
            }

//            String str1 = "<Msg><MsgID>1496224592</MsgID><From><![CDATA[wxid_mqj9t6xw4pq222]]></From><FromUin>609135128</FromUin><To><![CDATA[0]]></To><Type>3</Type><Content><![CDATA[<msg><imgmsg fileid=\"305f0201000458305602010002041e797b2502030f47b902049d7cabdc0204592e706f04343630393133353132385f3236343133333535355f37616432306333333733643135303732613636386238393633386630366331350201000201000400\" aeskey=\"70747768716e77627771656869776964\" /></msg>]]></Content><FromTime>1496224592</FromTime><Chatroom>7509673305</Chatroom><MediaID>0</MediaID><ClientIP><![CDATA[223.104.30.224]]></ClientIP><MediaURL>/fs/fhfs/v1/JL7a/20170531/http/nVAulO/574/629292/138599</MediaURL></Msg>";
//            JSONObject xmlJSONObj = XML.toJSONObject(str1);
//
//            System.out.println(xmlJSONObj.get("Msg").toString());
//
//            JSONObject json = new JSONObject(xmlJSONObj.get("Msg").toString());
//
////            System.out.println(json.get("From"));
//            System.out.println(json.get("Content"));
//            String str2 = json.get("Content").toString();
//            JSONObject arrStr = XML.toJSONObject(str2);
//            JSONObject json1 = new JSONObject(arrStr.get("msg").toString());
//            System.out.println();
//            System.out.println(json1.get("videomsg"));
        } catch (JSONException ex) {
            Logger.getLogger(test1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
